namespace Lapkin.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Users",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Email = c.String(nullable: false),
                        Password = c.String(nullable: false),
                        Name = c.String(),
                        Address = c.String(),
                        Phone = c.String(),
                        IsBanned = c.Boolean(nullable: false),
                        RegDate = c.DateTime(nullable: false),
                        LastActiveDate = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Roles",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Orders",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        OrderDate = c.DateTime(nullable: false),
                        Total = c.Decimal(nullable: false, precision: 18, scale: 2),
                        User_Id = c.Guid(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Users", t => t.User_Id)
                .Index(t => t.User_Id);
            
            CreateTable(
                "dbo.OrderDetails",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Quantity = c.Int(nullable: false),
                        UnitPrice = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Product_Id = c.Guid(),
                        Order_Id = c.Guid(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Products", t => t.Product_Id)
                .ForeignKey("dbo.Orders", t => t.Order_Id)
                .Index(t => t.Product_Id)
                .Index(t => t.Order_Id);
            
            CreateTable(
                "dbo.Products",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(nullable: false),
                        Description = c.String(),
                        Price = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Alias = c.String(nullable: false),
                        IsActive = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Categories",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(nullable: false),
                        Alias = c.String(nullable: false),
                        Parent_Id = c.Guid(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Categories", t => t.Parent_Id)
                .Index(t => t.Parent_Id);
            
            CreateTable(
                "dbo.Images",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Url = c.String(),
                        IsMainImage = c.Boolean(nullable: false),
                        Product_Id = c.Guid(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Products", t => t.Product_Id)
                .Index(t => t.Product_Id);
            
            CreateTable(
                "dbo.ProductPropertyProducts",
                c => new
                    {
                        ProductId = c.Guid(nullable: false),
                        PropertyId = c.Guid(nullable: false),
                        Value = c.String(),
                    })
                .PrimaryKey(t => new { t.ProductId, t.PropertyId })
                .ForeignKey("dbo.ProductProperties", t => t.PropertyId, cascadeDelete: true)
                .ForeignKey("dbo.Products", t => t.ProductId, cascadeDelete: true)
                .Index(t => t.PropertyId)
                .Index(t => t.ProductId);
            
            CreateTable(
                "dbo.ProductProperties",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ProductVariantProducts",
                c => new
                    {
                        ProductId = c.Guid(nullable: false),
                        VariantId = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => new { t.ProductId, t.VariantId })
                .ForeignKey("dbo.ProductVariants", t => t.VariantId, cascadeDelete: true)
                .ForeignKey("dbo.Products", t => t.ProductId, cascadeDelete: true)
                .Index(t => t.VariantId)
                .Index(t => t.ProductId);
            
            CreateTable(
                "dbo.ProductVariants",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ProductVariantValues",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Value = c.String(),
                        Discount = c.Decimal(nullable: false, precision: 18, scale: 2),
                        ProductVariantProduct_ProductId = c.Guid(),
                        ProductVariantProduct_VariantId = c.Guid(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ProductVariantProducts", t => new { t.ProductVariantProduct_ProductId, t.ProductVariantProduct_VariantId })
                .Index(t => new { t.ProductVariantProduct_ProductId, t.ProductVariantProduct_VariantId });
            
            CreateTable(
                "dbo.OrderVariants",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(),
                        Value = c.String(),
                        Discount = c.Decimal(nullable: false, precision: 18, scale: 2),
                        OrderDetail_Id = c.Guid(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.OrderDetails", t => t.OrderDetail_Id)
                .Index(t => t.OrderDetail_Id);
            
            CreateTable(
                "dbo.RoleUsers",
                c => new
                    {
                        Role_Id = c.Guid(nullable: false),
                        User_Id = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => new { t.Role_Id, t.User_Id })
                .ForeignKey("dbo.Roles", t => t.Role_Id, cascadeDelete: true)
                .ForeignKey("dbo.Users", t => t.User_Id, cascadeDelete: true)
                .Index(t => t.Role_Id)
                .Index(t => t.User_Id);
            
            CreateTable(
                "dbo.CategoryProducts",
                c => new
                    {
                        Category_Id = c.Guid(nullable: false),
                        Product_Id = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => new { t.Category_Id, t.Product_Id })
                .ForeignKey("dbo.Categories", t => t.Category_Id, cascadeDelete: true)
                .ForeignKey("dbo.Products", t => t.Product_Id, cascadeDelete: true)
                .Index(t => t.Category_Id)
                .Index(t => t.Product_Id);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.CategoryProducts", new[] { "Product_Id" });
            DropIndex("dbo.CategoryProducts", new[] { "Category_Id" });
            DropIndex("dbo.RoleUsers", new[] { "User_Id" });
            DropIndex("dbo.RoleUsers", new[] { "Role_Id" });
            DropIndex("dbo.OrderVariants", new[] { "OrderDetail_Id" });
            DropIndex("dbo.ProductVariantValues", new[] { "ProductVariantProduct_ProductId", "ProductVariantProduct_VariantId" });
            DropIndex("dbo.ProductVariantProducts", new[] { "ProductId" });
            DropIndex("dbo.ProductVariantProducts", new[] { "VariantId" });
            DropIndex("dbo.ProductPropertyProducts", new[] { "ProductId" });
            DropIndex("dbo.ProductPropertyProducts", new[] { "PropertyId" });
            DropIndex("dbo.Images", new[] { "Product_Id" });
            DropIndex("dbo.Categories", new[] { "Parent_Id" });
            DropIndex("dbo.OrderDetails", new[] { "Order_Id" });
            DropIndex("dbo.OrderDetails", new[] { "Product_Id" });
            DropIndex("dbo.Orders", new[] { "User_Id" });
            DropForeignKey("dbo.CategoryProducts", "Product_Id", "dbo.Products");
            DropForeignKey("dbo.CategoryProducts", "Category_Id", "dbo.Categories");
            DropForeignKey("dbo.RoleUsers", "User_Id", "dbo.Users");
            DropForeignKey("dbo.RoleUsers", "Role_Id", "dbo.Roles");
            DropForeignKey("dbo.OrderVariants", "OrderDetail_Id", "dbo.OrderDetails");
            DropForeignKey("dbo.ProductVariantValues", new[] { "ProductVariantProduct_ProductId", "ProductVariantProduct_VariantId" }, "dbo.ProductVariantProducts");
            DropForeignKey("dbo.ProductVariantProducts", "ProductId", "dbo.Products");
            DropForeignKey("dbo.ProductVariantProducts", "VariantId", "dbo.ProductVariants");
            DropForeignKey("dbo.ProductPropertyProducts", "ProductId", "dbo.Products");
            DropForeignKey("dbo.ProductPropertyProducts", "PropertyId", "dbo.ProductProperties");
            DropForeignKey("dbo.Images", "Product_Id", "dbo.Products");
            DropForeignKey("dbo.Categories", "Parent_Id", "dbo.Categories");
            DropForeignKey("dbo.OrderDetails", "Order_Id", "dbo.Orders");
            DropForeignKey("dbo.OrderDetails", "Product_Id", "dbo.Products");
            DropForeignKey("dbo.Orders", "User_Id", "dbo.Users");
            DropTable("dbo.CategoryProducts");
            DropTable("dbo.RoleUsers");
            DropTable("dbo.OrderVariants");
            DropTable("dbo.ProductVariantValues");
            DropTable("dbo.ProductVariants");
            DropTable("dbo.ProductVariantProducts");
            DropTable("dbo.ProductProperties");
            DropTable("dbo.ProductPropertyProducts");
            DropTable("dbo.Images");
            DropTable("dbo.Categories");
            DropTable("dbo.Products");
            DropTable("dbo.OrderDetails");
            DropTable("dbo.Orders");
            DropTable("dbo.Roles");
            DropTable("dbo.Users");
        }
    }
}
